<template>
	<view class="forum_wrap">
		<view class="flex nav_wrap">
			<view :class="nav_index == 0 ? 'nav_item active' : 'nav_item'" @click="toNav(0)">官方发布</view>
			<view :class="nav_index == 1 ? 'nav_item active' : 'nav_item'" @click="toNav(1)">活动</view>
		</view>
		<scroll-view scroll-y="true" style="height: calc(100vh - 118rpx);" v-if="nav_index == 0">
			<view class="list_wrap" v-for="(item,index) in notice_list">
				<view class="flex-col section_7" @click="toDetail(item.id)" v-if="item.image">
					<view class="flex-col items-start relative group_5">
						<text class="font row_1" style="width: 82%;">{{ item.title }}</text>
						<!-- <view class="font_2 text_7 row_1">{{ item.content }}</view> -->
						<!-- <rich-text class="font_2 text_7 row_1" style="width: 80%;" :nodes="item.content"></rich-text> -->
						<image class="image_8 pos_9" :src="ossUrl + item.image" />
					</view>
					<text class="self-start font_3 text_3 mt-14">{{ item.createtime }}</text>
					<view class="top_up" v-if="item.is_top_switch == 1">置顶</view>
				</view>
				<view class="flex-col section_7" @click="toDetail(item.id)" v-else>
					<view class="flex-col items-start relative group_5">
						<text class="font">{{ item.title }}</text>
						<!-- <view class="font_2 text_7 row_1" style="width: 100%;">{{ item.content }}</view> -->
						<!-- <rich-text class="font_2 text_7 row_1" style="width: 100%;" :nodes="item.content"></rich-text> -->
					</view>
					<text class="self-start font_3 text_3 mt-14">{{ item.createtime }}</text>
					<view class="top_up" v-if="item.is_top_switch == 1">置顶</view>
				</view>
			</view>
		</scroll-view>
		<scroll-view scroll-y="true" style="height: calc(100vh - 118rpx);" v-if="nav_index == 1">
			<view class="list_wrap" v-for="(item,index) in activity_list">
				<view class="flex-col list-item" @click="toActivity(item.id)">
					<view class="flex-row">
						<image class="shrink-0 image_8" :src="ossUrl + item.image" />
						<view class="flex-col flex-1 group_5 ml-10">
							<text class="font_2">{{ item.title }}</text>
							<text class="mt-16 font_3 text_2">活动地址：{{ item.address }}</text>
						</view>
					</view>
					<view class="flex-row justify-between items-center mt-8">
						<text class="font_4 text_2">开始时间：{{ item.start_time }}</text>
						<view :class="[(new Date().getTime() < new Date(item.start_time).getTime()) ? 'button' : (new Date().getTime() > new Date(item.start_time).getTime() && (new Date().getTime() < new Date(item.end_time).getTime())) ? 'button_1' : 'button_2','flex']">
							<text class="font_5">{{ new Date().getTime() < new Date(item.start_time).getTime() ? '报名中' : (new Date().getTime() > new Date(item.start_time).getTime() && (new Date().getTime() < new Date(item.end_time).getTime())) ? '已开始' : '已结束' }}</text>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		remoteUrl,
		ossUrl
	} from '@/utils/config.js'
	import {
		getNotice,
		getActivity
	} from '@/api/forum.js'
	export default {
		data() {
			return {
				ossUrl: ossUrl,
				remoteUrl: remoteUrl,
				nav_index: 0,
				notice_list: [],
				activity_list: []
			}
		},
		onLoad() {
			this.getNoticeFun()
			this.getActivityFun()
		},
		onShareAppMessage(res) { //发送给朋友
			return {
				title: '小程序分享',
				imageUrl: '',
			}
		},
		methods: {
			// 获取公告列表
			getNoticeFun() {
				getNotice().then(res => {
					if (res.code == 1) {
						this.notice_list = res.data
					}
				})
			},
			// 获取活动列表
			getActivityFun() {
				getActivity().then(res => {
					if (res.code == 1) {
						this.activity_list = res.data
					}
				})
			},
			toNav(index) {
				this.nav_index = index
			},
			toDetail(id) {
				uni.navigateTo({
					url: '../forum_detail/forum_detail?id=' + id
				})
			},
			toActivity(id) {
				uni.navigateTo({
					url: '../activity_detail/activity_detail?id=' + id
				})
			},
		},
	}
</script>

<style lang="scss" scoped>
	.forum_wrap {
		min-height: 100vh;
		background: #F6F8FF;

		.nav_wrap {
			width: 100vw;
			height: 96rpx;
			align-items: center;
			padding: 0 28rpx;
			background: #fff;
			margin-bottom: 20rpx;

			.nav_item {
				font-size: 32rpx;
				color: #989595;
				margin-right: 80rpx;
			}

			.active {
				color: #1C41F1;
				font-weight: bold;
				position: relative;
			}

			.active::after {
				content: "";
				width: 60rpx;
				border-bottom: 6rpx solid #1C41F1;
				position: absolute;
				bottom: -10rpx;
				left: 50%;
				transform: translate(-50%);
			}
		}

		.list_wrap {
			margin-bottom: 20rpx;

			.section_7 {
				width: 690rpx;
				margin: 0 auto;
				padding: 22rpx 22rpx 34rpx;
				background-color: #ffffff;
				border-radius: 10rpx;
				position: relative;
				.top_up {
					padding: 6rpx 8rpx;
					color: #fff;
					font-size: 26rpx;
					background: #70D042;
					position: absolute;
					top: 15rpx;
					right: 15rpx;
					border-radius: 4rpx;
				}
				.group_5 {
					padding: 8rpx 0 18rpx;

					.font {
						font-size: 32rpx;
						color: #000000;
					}

					.font_2 {
						font-size: 26rpx;
						color: #000000;
					}

					.text_7 {
						width: 80%;
						opacity: 0.8;
						margin-top: 24rpx;
					}

					.image_8 {
						border-radius: 10rpx;
						width: 100rpx;
						height: 100rpx;
					}

					.pos_9 {
						position: absolute;
						right: 0;
						bottom: -80rpx;
					}
				}

				.font_3 {
					font-size: 22rpx;
					color: #000000;
				}

				.text_3 {
					opacity: 0.5;
				}
			}


			.list-item {
				width: 690rpx;
				margin: 0 auto;
				padding: 24rpx 24rpx 16rpx;
				background-color: #ffffff;
				border-radius: 10rpx;

				.image_8 {
					border-radius: 10rpx;
					width: 240rpx;
					height: 180rpx;
				}

				.group_5 {
					margin-right: 4rpx;

					.font_2 {
						font-size: 30rpx;
						color: #000000;
					}

					.font_3 {
						font-size: 24rpx;
						color: #000000;
					}
				}

				.font_4 {
					font-size: 24rpx;
					color: #000000;
				}

				.text_2 {
					opacity: 0.5;
				}

				.button {
					padding: 5rpx 10rpx;
					background-color: #1c41f1;
					border-radius: 8rpx;

					.font_5 {
						font-size: 26rpx;
						color: #ffffff;
					}
				}
				.button_1 {
					padding: 5rpx 10rpx;
					background-color: #70D042;
					border-radius: 8rpx;
				
					.font_5 {
						font-size: 26rpx;
						color: #ffffff;
					}
				}
				.button_2 {
					padding: 5rpx 10rpx;
					background-color: #808080;
					border-radius: 8rpx;
				
					.font_5 {
						font-size: 26rpx;
						color: #ffffff;
					}
				}
			}
		}
	}
</style>